package com.lx.base;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author lixing
 * @date 2022/7/20 17:20
 */
public class BaseRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        List<String> packs=new ArrayList<String>();
        packs.add("com.lx.base");
        Map<String ,Object> attr=importingClassMetadata.getAnnotationAttributes(EnableBaseConfig.class.getName());
       if((boolean)attr.get("useDateConverter")) {
           packs.add("com.lx.base.config.converter");
       }
        ClassPathBeanDefinitionScanner scanner=new ClassPathBeanDefinitionScanner(registry);
        scanner.scan((String[])packs.toArray());
    }
}
